require "lib/inifile"
require "lib/ini"
require "ftools"

puts " ----------------------------"
puts "|   /\\  P R E F E R E N C E S|%"
puts "|  /__\\      E D I T O R     |%"
puts "| /\\  /\\                     |%"
puts "|/__\\/__\\     WW-P COLLAB    |%"
puts "|             LOZ PROJECT    |%"
puts "|----------------------------|%"
puts "|Press <ENTER> to continue...|%"
puts " ----------------------------\\%"
puts " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%"

STDIN.gets

print "\n\n\n\n\n"

system("cls")

puts "Loading ini..."

optionsconstr = [
  Ini::Option.new("Appearance::Fullscreen", ["True","False",0,1], "True"),
  Ini::Option.new("Debug::Enabled", ["True","False",0,1], "True"),
  Ini::Option.new("Debug::ConsoleEnabled", ["True","False",0,1], "True"),
  Ini::Option.new("Debug::TraceEnabled", ["True","False",0,1], "True"),
  Ini::Option.new("Debug::AutoTrace", ["True","False",0,1], "True"),
  Ini::Option.new("Logger::Mode", ["Off","Disabled","Auto","Custom"], "Auto"),
  Ini::Option.new("Logger::Level", ["Debug","Info","Warning","Warn","Error","Fatal","Auto"], "Auto")
]

ARGV[0]="../app.ini" if ARGV[0]==nil

ini=Ini.new(ARGV[0])

optionsconstr.each { |oc|
  ini.loadOption(oc)
}

ini.validate

puts "Ini is valid.\n\n"



while true

  sections=[]
  i=1

  puts "Sections:"

  ini.sections { |section|
    if sections.index(section.upcase)==nil
      sections.push(section.upcase)
      puts i.to_s+".) "+section.capitalize
      i+=1
    end
  }

  print "X.) <Exit>\n\nView Section: "
  i=STDIN.gets.chomp
  if i=="X" or i=="x"
    exit
  else
    i=i.to_i
  end

  puts "\n\n"

  raise ArgumentError.new if (i<1 or i>sections.size)

  section=sections[i-1]

  options=[]
  i=1

  while true

    puts section.capitalize+":"

    ini[section].each { |option, value|
      if options.index(option.upcase)==nil
        options.push(option.upcase)
        puts i.to_s+".) "+option.capitalize+" => '"+value.to_s.capitalize+"'"
        i+=1
      end
    }

    puts "S.) <Return to Sections>"
    print "X.) <Exit>\n\nView Option: "
    i=STDIN.gets.chomp
    if i=="X" or i=="x"
      exit
    elsif i=="S" or i=="s"
      break
    else
      i=i.to_i
    end

    puts "\n\n"
  
    raise ArgumentError.new if (i<1 or i>options.size)
    
    option=options[i-1]
    value=ini[section][option]
    
    print section.capitalize+"."+option.capitalize+":\nValue: '"+value.to_s.capitalize+"'\n1.) Edit Value\nO.) <Return to Section '"+section.capitalize+"'>\nS.) <Return to Sections>\nX.) <Exit>\n"
    print "\n\nCommand: "
    i=STDIN.gets.chomp
    if i=="1"
      
    elsif i=="O" or i=="o"
      
    elsif i=="S" or i=="s"
      break
    elsif i=="X" or i=="x"
      exit
    else
      i=i.to_i
    end

  end
  
end